<?php
namespace addons\TfFutures\common\models;

use yii\db\ActiveRecord;

class Logs extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_tf_futures_logs}}';
    }


    public function rules()
    {
        return [];
    }

    public function attributeLabels()
    {
        return [
            'id'         => 'ID',
            'type'       => '日志类型',
            'price'      => '涉及金额',
            'price_old'  => '原先余额',
            'price_new'  => '最新余额',
            'desc'       => '详细描述',
            'status'     => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 记录日志
     * @param $member_id      用户id
     * @param $type           日志类型
     * @param $price          涉及金额
     * @param $price_old      原先余额
     * @param $price_new      最新余额
     * @param $desc           详细描述
     *
     */
    public static function addLogs($member_id,$type,$price,$price_old,$price_new,$desc){
        $logsModel = new self();
        $logsModel->member_id = $member_id;
        $logsModel->type = $type;
        $logsModel->price = $price;
        $logsModel->price_old = $price_old;
        $logsModel->price_new = $price_new;
        $logsModel->desc = $desc;
        $logsModel->created_at = time();
        $logsModel->updated_at = time();
        $logsModel->save();
    }
    public function getMember(){
        return $this->hasOne(\common\models\member\Member::className(),['id'=>'member_id']);
    }
}
